package com.open4cn.simulator.connect.com;

import com.open4cn.simulator.connect.com.handler.DispatcherHandler;
import com.open4cn.simulator.connect.com.handler.ReadBlockHandler;
import com.open4cn.simulator.connect.com.handler.ReadLogAfterDecodeHandler;
import com.open4cn.simulator.connect.com.handler.WriteLogHandler;
import com.open4cn.simulator.connect.com.listenner.ConnectStatusListener;
import com.open4cn.simulator.core.device.DeviceStatus;
import com.open4cn.simulator.core.parser.InstructionParserChain;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-08-07 18:55
 */
public class SerialPortQuickConnector extends SerialPortConnector {

    public SerialPortQuickConnector(DeviceStatus deviceStatus, InstructionParserChain chain) {
        super();
        init(deviceStatus, chain);
    }

    private void init(DeviceStatus deviceStatus, InstructionParserChain chain) {
        beforeDecod(new ReadBlockHandler(deviceStatus));
        afterDecod(new ReadLogAfterDecodeHandler(deviceStatus.getDeviceName()));
        afterDecod(new DispatcherHandler(chain));
        afterEncod(new WriteLogHandler(deviceStatus.getDeviceName()));
        addOpenListenner(new ConnectStatusListener(this.getConnectStatus()));
    }
}
